<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>字典组</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding:10px"><h2>Dictionary</h2></div>
<div data-options="region:'west',split:true,title:'主菜单'" style="width:156px;padding:0px;">
<div class="easyui-accordion" data-options="fit:true,border:false">
<div title="域对象清单" style="padding:0px" data-options="selected:true">
<div id="mmadmin" data-options="inline:true" style="width: 142px; height: 98%; overflow: hidden; left: 0px; top: 0px; outline: none; display: block;" class="menu-top menu-inline menu easyui-fluid" tabindex="0"><div class="menu-line" style="height: 122px;"></div>
<div onclick="window.location='../pages/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">主页</div><div class="menu-icon icon-add"></div></div>

<div onclick="window.location='../pages/dicgroups.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">字典组</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/dictionarys.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">字典</div><div class="menu-icon icon-add"></div></div>
</div>
</div>
</div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'属性'" style="width:250px;overflow: hidden">
</div>
<div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;text-align: center">火箭船软件工作室版权所有。作者电邮:jerry_shen_sjf@qq.com QQ群:277689737</div>
<div data-options="region:'center',title:'字典组清单'">
<div title="搜索面板" class="easyui-panel" style="width:1120px;height:200px">
<form id="ffsearch" method="post">
<table cellpadding="5">
<tr>
<td>父项序号:</td><td><input  class='easyui-combobox' type='text' name='parentId' id='parentId' value='' data-options="required:false,valueField:'dicGroupId',textField:'dicGroupName',method:'post',url:'../facade/listActiveDicGroupsFacade',loadFilter:function(data){return data.rows}"/></td>
<td>字典组键值:</td><td><input class='easyui-textbox' type='text' name='dicGroupKey' id='dicGroupKey' value='' data-options="required:false"/></td>
<td>字典组值:</td><td><input class='easyui-textbox' type='text' name='dicGroupValue' id='dicGroupValue' value='' data-options="required:false"/></td></tr>
</tr>
<tr>
<td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td>
<td>字典组名称:</td><td><input class='easyui-textbox' type='text' name='dicGroupName' id='dicGroupName' value='' data-options="required:false"/></td>
<td>活跃:</td><td><input class='easyui-textbox' type='text' name='active' id='active' value='' data-options="required:false"/></td></tr>
</tr>
<tr><td colspan="3"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchDicGroupsByFieldsByPage()">搜索</a></td></tr>
</table>
</form>
</div>
<table id="dg" class="easyui-datagrid" title="字典组清单" style="width:1120px;height:400px" data-options="singleSelect:false,url:'../facade/searchDicGroupsByFieldsByPageFacade',queryParams:params,method:'post',pagination:true,toolbar:toolbar">
<thead>
<tr>
<th data-options="field:'dicGroupId',checkbox:true">字典组序号</th>
<th data-options="field:'parentId',width:80,formatter:selfTranslateDicGroup">父项序号</th>
<th data-options="field:'dicGroupKey',width:80">字典组键值</th>
<th data-options="field:'dicGroupValue',width:80">字典组值</th>
<th data-options="field:'description',width:80">描述</th>
<th data-options="field:'dicGroupName',width:80">字典组名称</th>
<th data-options="field:'active',width:80">活跃</th>
</tr>
</thead>
</table>
</div>

<div class="easyui-window" title="新增字典组" id="waddDicGroup" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:550px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<tr><td>父项序号:</td><td><input  class='easyui-combobox' type='text' name='parentId' id='parentId' value='' data-options="required:false,valueField:'dicGroupId',textField:'dicGroupName',method:'post',url:'../facade/listActiveDicGroupsFacade',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>字典组键值:</td><td><input  class='easyui-textbox' type='text' name='dicGroupKey' id='dicGroupKey' value='' data-options="required:false"/></td></tr>
<tr><td>字典组值:</td><td><input  class='easyui-textbox' type='text' name='dicGroupValue' id='dicGroupValue' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td></tr>
<tr><td>字典组名称:</td><td><input  class='easyui-textbox' type='text' name='dicGroupName' id='dicGroupName' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addDicGroup()">新增</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#waddDicGroup').window('close')">取消</a>
</div>
</div>

<div class="easyui-window" title="编辑字典组" id="wupdateDicGroup" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:500px;height:500px">
<div style="padding:10px 60px 20px 60px">
<form id="ffedit" method="post">
<input  type='hidden' name='dicGroupId' id='dicGroupId' value=''/>
<table cellpadding="5">
<tr><td>父项序号:</td><td><input  class='easyui-combobox' type='text' name='parentId' id='parentId' value='' data-options="required:false,valueField:'dicGroupId',textField:'dicGroupName',method:'post',url:'../facade/listActiveDicGroupsFacade',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>字典组键值:</td><td><input  class='easyui-textbox' type='text' name='dicGroupKey' id='dicGroupKey' value='' data-options="required:false"/></td></tr>
<tr><td>字典组值:</td><td><input  class='easyui-textbox' type='text' name='dicGroupValue' id='dicGroupValue' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td></tr>
<tr><td>字典组名称:</td><td><input  class='easyui-textbox' type='text' name='dicGroupName' id='dicGroupName' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateDicGroup()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ffedit').form('clear');">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wupdateDicGroup').window('close')">取消</a>
</div>
</div>
</body>
<script type="text/javascript">
var params = {};
var pagesize = 10;
var pagenum = 1;
var toolbar = [
{
	text:'新增',
	iconCls:'icon-add',
	handler:function(){
		$('#waddDicGroup').window('open');
	}
}
,
{
	text:'编辑',
	iconCls:'icon-edit',
	handler:function(){ 
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		parentId = rows[0]["parentId"];
		if (parentId == undefined|| parentId == null || parentId <= 0 || parentId=="0") parentId = null;
		$("#ffedit").find("#dicGroupId").val(rows[0]["dicGroupId"]);
		$("#ffedit").find("#parentId").combobox("setValue",parentId);
		$("#ffedit").find("#dicGroupKey").textbox("setValue",rows[0]["dicGroupKey"]);
		$("#ffedit").find("#dicGroupValue").textbox("setValue",rows[0]["dicGroupValue"]);
		$("#ffedit").find("#description").textbox("setValue",rows[0]["description"]);
		$("#ffedit").find("#dicGroupName").textbox("setValue",rows[0]["dicGroupName"]);
		var checkboxs = $("#ffedit").find("input[name='active']");
		for (var i=0;i<checkboxs.size();i++){
			if (checkboxs.get(i).value == ""+rows[0]["active"]) checkboxs.get(i).checked=true;
		}
		$('#wupdateDicGroup').window('open');
	}
}
,
{
	text:'软删除',
	iconCls:'icon-remove',
	handler:function(){ 
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var dicGroupId = rows[0]["dicGroupId"];
		softDeleteDicGroup(dicGroupId);
	}
}
,
{
	text:'删除',
	iconCls:'icon-remove',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if ($.messager.confirm("警告","确认要删除选定记录吗？", function(data){
			if (data){
				if (rows.length > 1) {
					$.messager.alert("警告","请选定一条记录！","warning");
					return;
				}
				var dicGroupId = rows[0]["dicGroupId"];
				deleteDicGroup(dicGroupId);
			}
		}));
}
}
,
{
	text:'切换',
	iconCls:'icon-cut',
	handler:function(){ 
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var dicGroupId = rows[0]["dicGroupId"];
		toggleDicGroup(dicGroupId);
	}
}
,
{
	text:'留一切换',
	iconCls:'icon-cut',
	handler:function(){ 
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var dicGroupId = rows[0]["dicGroupId"];
		toggleOneDicGroup(dicGroupId);
	}
}
,'-',
{
	text:'批软删除',
	iconCls:'icon-remove',
	handler:function(){ 
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定记录！","warning");
			return;
		}
		var ids = "";
		for(var i=0;i<rows.length;i++){
			ids += rows[i]["dicGroupId"];
			if (i < rows.length-1) ids += ",";
		}
		softDeleteAllDicGroups(ids);
	}
}
,
{
	text:'批删除',
	iconCls:'icon-remove',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定记录！","warning");
			return;
		}
		if ($.messager.confirm("警告","确认要删除选定记录吗？",function(data){
			if (data){
				var ids = "";
				for(var i=0;i<rows.length;i++){
					ids += rows[i]["dicGroupId"];
					if (i < rows.length-1) ids += ",";
				}
				deleteAllDicGroups(ids);
			}
		}));
	}
}
];
$(document).ready(function(){
$("#dg").datagrid("load");
});
function clearForm(){
$('#ff').form('clear');
}
function addDicGroup(){
	if ($("#ff").form("validate")) {
		$.ajax({
			type: "post",
			url: "../facade/addDicGroupFacade",
			data:{
				parentId:$("#ff").find("#parentId").combobox("getValue"),
				dicGroupKey:$("#ff").find("#dicGroupKey").val(),
				dicGroupValue:$("#ff").find("#dicGroupValue").val(),
				description:$("#ff").find("#description").val(),
				dicGroupName:$("#ff").find("#dicGroupName").val(),
				active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
			},
			success: function(data, textStatus) {
				if (data.success) {
					$('#ff').form('clear');
					$("#ff").find("input[name='active']").get(0).checked = true;
					$("#waddDicGroup").window('close');
					$("#dg").datagrid("load");
				}
				},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function(XMLHttpRequest,textStatus,errorThrown) {
				alert("Error:"+textStatus);
				alert(errorThrown.toString());
			}
		});
	}
}

function updateDicGroup(){
	$.ajax({
		type: "post",
		url: "../facade/updateDicGroupFacade",
		data:{
			parentId:$("#ffedit").find("#parentId").combobox("getValue"),
			dicGroupKey:$("#ffedit").find("#dicGroupKey").val(),
			dicGroupValue:$("#ffedit").find("#dicGroupValue").val(),
			description:$("#ffedit").find("#description").val(),
			dicGroupName:$("#ffedit").find("#dicGroupName").val(),
			active:parseBoolean($("#ffedit").find("input[name='active']:checked").val()),
			dicGroupId:$("#ffedit").find("#dicGroupId").val(),
		},
		success: function(data, textStatus) {
			if (data.success){
				$('#ffedit').form('clear');
				$("#ffedit").find("input[name='active']").get(0).checked = true;
				$("#wupdateDicGroup").window('close');
				$("#dg").datagrid("load");
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	}); 
}

function softDeleteDicGroup(dicGroupId){
	$.ajax({
		type: "post",
		url: "../facade/softDeleteDicGroupFacade",
		data: {
			"dicGroupId":dicGroupId	
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteDicGroup(dicGroupId){
	$.ajax({
		type: "post",
		url: "../facade/deleteDicGroupFacade",
		dataType: 'json',
		data:{"dicGroupId":dicGroupId},
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	}); 
}

function toggleDicGroup(dicGroupId){
	$.ajax({
		type: "post",
		url: "../facade/toggleDicGroupFacade",
		data: {
			"dicGroupId":dicGroupId
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function toggleOneDicGroup(dicGroupId){
	$.ajax({
		type: "post",
		url: "../facade/toggleOneDicGroupFacade",
		data: {
			"dicGroupId":dicGroupId
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function softDeleteAllDicGroups(ids){
	$.ajax({
		type: "post",
			url: "../facade/softDeleteAllDicGroupsFacade",
			data: {
				ids:ids
			},
			dataType: 'json',
			success: function(data, textStatus) {
				$("#dg").datagrid("load");
			},
			complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteAllDicGroups(ids){
	$.ajax({
		type: "post",
		url: "../facade/deleteAllDicGroupsFacade",
		data: {
			ids:ids
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function searchDicGroupsByFieldsByPage(){
	params = {
		parentId:$("#ffsearch").find("#parentId").val(),
		dicGroupKey:$("#ffsearch").find("#dicGroupKey").val(),
		dicGroupValue:$("#ffsearch").find("#dicGroupValue").val(),
		description:$("#ffsearch").find("#description").val(),
		dicGroupName:$("#ffsearch").find("#dicGroupName").val(),
		active:parseBoolean($("#ffsearch").find("#active").val()),
	};
	$("#dg").datagrid({queryParams:params});
}

function parseBoolean(val){
	if (val == undefined|| val == null) return false;
	var isInt = /^(-}+)?\d+$/.test(val);
	if (isInt&& val == "0") return false;
	else if (isInt&& val == "1") return true;
	else if (val.toLowerCase() == "false") return false;
	else if (val.toLowerCase() == "true") return true;
	else if (val.toLowerCase() == "f") return false;
	else if (val.toLowerCase() == "t") return true;
	else if (val.toLowerCase() == "n") return false;
	else if (val.toLowerCase() == "y") return true;
	else if (val.toLowerCase() == "no") return false;
	else if (val.toLowerCase() == "yes") return true;
	else return "";
}
function isBlank(val){
	if (val == undefined|| val == null || val == "") return true;
	else return false;
}
function checkRadioBoxValue(control,field,fieldvalue){
	var checkboxs = $("#"+control).find("input[name='"+field+"']");
	for (var i=0;i<checkboxs.size();i++){
		if (checkboxs.get(i).value == ""+fieldvalue) checkboxs.get(i).checked=true;
	}
}
function selfTranslateDicGroup(value){
	if (value== undefined || value==null||value=="" || value <= 0 || value == "0") 
		return "";
	var retVal = value;
	$.ajax({
		type:"post",
		url: "../facade/findDicGroupByDicGroupIdFacade",
		data: {
			dicGroupId:value
		},
		dataType: 'json',
		async:false,
		success: function(data, textStatus) {
			debugger;
			retVal = data.data.dicGroupName;
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
	return retVal;
}
</script>
</html>
